// Using the closure to map jQuery to $. 
(function ($) {

// Store our function as a property of Drupal.behaviors.
Drupal.behaviors.edit = {
	attach: function(context, settings) {
		$(".form-item-files-package-file").hide();
		$('#edit-use-old-file').change(function() {
		    var $this = $(this);
		    // $this will contain a reference to the checkbox   
	    	
	    	if ($this.is(':checked')) {
	            // the checkbox was checked
	    		$(".form-item-files-package-file").hide();
	        } else {
	            // the checkbox was unchecked
	        	$(".form-item-files-package-file").show();
	        }
		});
		$('#edit-package-type').change(function(){
			var new_val = $(this).val();
			
			$('select [selected]').each(function() {
				var org_val = $(this).val();
				if (new_val != org_val) {
					$('#edit-use-old-file').prop('checked', false);
					$('#edit-use-old-file').change();
					$('.form-item-use-old-file').hide();
				}
				else {
					$('#edit-use-old-file').prop('checked', true);
					$('#edit-use-old-file').change();
					$('.form-item-use-old-file').show();
				}
			});
		});
	}
};
}(jQuery));